function f=ict (coef,identifier,mode)
%inverse curvelet transformation
%f=ict (coef,identifier)
%
%use f=ict(coef,identifier,mode) with mode according to get_fourier_mask if
%you want to apply an additional fourier window before the inverse fourier
%transformation.
%
%
%author: Sebastian Schmelcher version: 2012-06-20


%identiffier recognision
%identifier can be used to set the mode. Therefore identifier must be a
%cell with the following structure:
% {{identifier},{[bool_ct bool_ict]},{mode}}
% where bool_ict determines of mode is used during the ict mehtod
%



mode_bool=false;
if(nargin>2)
    mode_bool=true;
end

if(iscell(identifier))
   if(length(identifier)>1)
       mode_bool=identifier{2}(2);
       if(mode_bool)
           mode=identifier{3};
       end
   end
   identifier=identifier{1};
end

imSize=size(coef{1}{1});



printLog=1;%0=OFF,1=short info, 2=full info


num_radial=length(coef)-1;

low=coef{end};

f_hat=fftshift(fft2(low)).*get_curvelet(identifier,imSize,0,0);


if(printLog==1)
    fprintf(['ict (' num2str(num_radial) '): ']);
end

for radial=1:num_radial
    if(printLog>0)
        if(printLog>1)
            fprintf(['ict: Iteration ' num2str(radial) ' of ' num2str(num_radial) '\n']);
        else
            fprintf('.');
            if(radial==num_radial)
                fprintf('\n');
            end
        end
    end
    num_angular=length(coef{radial});
    for angular=1:num_angular
        if(printLog>1)
            fprintf('.');
            if(angular==num_angular)
                fprintf('\n');
            end
        end
        if(sum(abs(coef{radial}{angular}(:)))>0)

            curvelet=get_curvelet(identifier,imSize,radial,angular);
            %curvelet=ifftshift(ifft2(curvelet));
            %f=f+coef{radial}{angular}.*curvelet;  %hier muss noch gearbeitet werden
            f_hat=f_hat+fftshift(fft2(coef{radial}{angular})).*curvelet;%.*curvelet;

        end
    end
end 
 

if(mode_bool)
    f_hat=f_hat.*get_fourier_mask(mode,imSize);
end

f=real(ifft2(ifftshift(f_hat)));